<template>
  <div>
    <p style="text-align: center;">{{ query.className }}班级作业</p>
    <el-form :inline="true" size="small">
      <el-table :loading="loading" :data="tableData" style="width: 98%;" size="small" row-key="id">
        <el-table-column prop="courseName" label="课程名称" />
        <el-table-column label="状态">
          <template #default="scope">
            <span>{{ scope.row.courseNum === scope.row.workStatus ? '已批改' : '未批改' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <div>
              <el-link type="primary" style="margin-right: 10px"
                @click="goToStudentWork(scope.row.courseName)">批改</el-link>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="demo-pagination-block" style="margin-top: 20px">
        <el-pagination size="small" v-model:current-page="page" v-model:page-size="size" :page-sizes="[5,10,15,20]"
            :total="pagination.total" :background="true" layout="total, sizes, prev, pager, next" @size-change="handleSizeChange"
            @current-change="handleCurrentChange" />
    </div>
    </el-form>
  </div>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import axios from "@/axios/index.js";
import { useRoute, useRouter } from "vue-router";
import { useNavigationStore } from "@/stores/navigation";

const router = useRouter();
const route = useRoute();
const query = ref()

console.log(query);


let tableData = reactive([]);
let loading = ref(true);

const page = ref(1) //当前页
const size = ref(5) //每页显示条数
let pagination = reactive({
    total:0,
    currentPage: 1,
    pageSize: 5
})

function loadTableData() {
  loading.value = true;
  axios
    .get("courseHomeworkRecord/select", {
      params: {
        current: pagination.currentPage,
        size: pagination.pageSize,
        classId: query.value.id,
      },
    })
    .then((resp) => {
      loading.value = false;
      const data = resp.data.data;
      tableData = data.records;
      pagination.total = data.total;
    });
}

function goToStudentWork(courseName,classId) {
  classId=query.value.id
  router.push({ path: '/classManagement/workandcorrect/StudentWork', query: { courseName ,classId} });
}

function handleCurrentChange(page) {
  pagination.currentPage = page;
  loadTableData();
}

function handleSizeChange(params) {
    pagination.pageSize=params
    loadTableData()
  }

if ((typeof route.query.query) != "undefined") {
  query.value = JSON.parse(route.query.query)
} else {
  query.value = {
    id: route.query.id,
    className: route.query.className
  }
}


loadTableData();



</script>

<style scoped></style>